package com.hkd.common.data.config.type_handler;

import com.hkd.common.api.enums.SupplierType;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Component;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author HKD
 * @date 2022/9/17 22:05
 */
@Component
public class SupplierTypeHandler extends BaseTypeHandler<SupplierType> {
    @Override
    public void setNonNullParameter(PreparedStatement preparedStatement, int i, SupplierType supplierType, JdbcType jdbcType) throws SQLException {
        preparedStatement.setInt(i,supplierType.getCode());
    }

    @Override
    public SupplierType getNullableResult(ResultSet resultSet, String s) throws SQLException {
        return SupplierType.search(resultSet.getInt(s));
    }

    @Override
    public SupplierType getNullableResult(ResultSet resultSet, int i) throws SQLException {
        return SupplierType.search(resultSet.getInt(i));
    }

    @Override
    public SupplierType getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
        return SupplierType.search(callableStatement.getInt(i));
    }
}
